package serial;

import java.io.File;
import java.io.IOException;

public class PortChecker {
	private static final boolean debug = false;
	
	public static boolean isPortActive(String portName) {
		try {
			Process p = Runtime.getRuntime().exec(CmdSender.CMD + " " + portName + " -checkPort");
			int result = p.waitFor();
			if (debug) {System.out.println("result from isPortActive(" + portName + "): " + result);}
			return (result == 0);
		} catch (IOException e) {
			if (debug) {
				e.printStackTrace();
			}
			return false;
		} catch (InterruptedException e) {
			return false;
		}
	}

	public static void main(String[] args) {
		if (debug) {
			File f = new File(".");
			for (String file: f.list()) {
				System.out.println(file);
			}
		}
        System.out.println(isPortActive(args[0]));
    }
}
